package com.eboss2.sbs.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * 通用适配器,用于ListView,GridView
 * 
 * @author yang
 * @since 2016-8-29 下午6:48:43
 */
public abstract class CommonAdapter<T> extends BaseAdapter {
	private List<T> mTs;
	private int mLayoutId;

	/**
	 * 
	 * @param ts
	 *            数据列表(泛型)
	 * @param layoutId
	 *            布局id
	 * @param isEnabled
	 *            是否可用(是否可点击);
	 */
	public CommonAdapter(List<T> ts, int layoutId) {
		this.mTs = ts;
		this.mLayoutId = layoutId;
	}

	@Override
	public int getCount() {
		return mTs.size();
	}

	@Override
	public T getItem(int position) {
		return mTs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View layout, ViewGroup parent) {
		CommonViewHolder viewHolder = CommonViewHolder.getInstance(layout,
				mLayoutId);
		setViewData(position, viewHolder, getItem(position));
		return viewHolder.getLayout();
	}

	/** 实现控件与数据的绑定 */
	public abstract void setViewData(int position, CommonViewHolder viewHolder,
			T vo);

}